/**
 * Copyright 2006 Brad Reynolds
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.leeloo.databinding.internal.ui;

import org.eclipse.jface.viewers.TreeNode;

/**
 * {@link TreeNode} that allows for the setting of the label.
 * 
 * @author Brad Reynolds
 */
public class LabeledTreeNode extends TreeNode {
    /**
     * Label to display for the node.
     */
    private String label;

    /**
     * Constructs a new instance.
     * 
     * @param value
     */
    public LabeledTreeNode(Object value) {
        super(value);
    }

    /**
     * @return label, can be <code>null</code>
     */
    public String getLabel() {
        return label;
    }

    /**
     * @param label
     *            label to set
     */
    public void setLabel(String label) {
        this.label = label;
    }

    /**
     * The {@link #equals(Object)} implementation of {@link TreeNode} assumes
     * that all nodes are unique and compares values rather than node
     * instances. Overriding so that equality is based on identify of the node.
     * 
     * @see org.eclipse.jface.viewers.TreeNode#equals(java.lang.Object)
     */
    public boolean equals(Object object) {
        return this == object;
    }

    /**
     * The {@link #hashCode()} implementation of {@link TreeNode} assumes that
     * all nodes are unique and compares the value rather than the node
     * instance. Overriding so that hashCode is computed off the node.
     * 
     * @see org.eclipse.jface.viewers.TreeNode#equals(Object)
     */
    public int hashCode() {
        return System.identityHashCode(this);
    }
}
